import {
    Dispatch
} from 'redux';

import Ajax from './../../http';

import * as types from './../types/discover';

interface DiscoverPara {
    limit?:number,
    lastId:never
}

export default {
    [types.getDiscoverList](para:DiscoverPara) {
        return async (dispatch:Dispatch) => {
            const {
                lastId,
                limit = 20
            } = para;

            const _data = {
                limit: limit,
                lastId: lastId,
                searchType: 'discover',
                startCond: 'user_search_result_id >'
            }

            try {
                const list = await Ajax.get(
                   `users`,_data
                )
                dispatch({
                    data:list,
                    type:types.getDiscoverList
                })
                return list;
            }
            catch (e) {
                return Promise.reject(e);
            }
        }
    }
}